package com.x.Servlet_06_请求转发;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * ClassName: forward
 * Package: IntelliJ IDEA
 * Description:
 1、请求转发是通HttpServletRequest对象实现的
 2、请求转发是服务器内部行为，对客户端是屏蔽的
 3、客户端只产生了一次请求，服务端只产生了一对request和response对象
 4、客户端的地址栏不变
 5、请求的参数继续转递给下一个Servlet
 6、WEB-INF下受保护资源可以通过请求转发访问到（唯一访问方式），但是直接访问（浏览器地址）不能访问WEB-INF下资源

 * Written by HanXu
 * Create 2024.08.11 1:45
 */

@WebServlet("/ServletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(" Do ServletA ! ");

        //1、获取请求转发器
        RequestDispatcher requestDispatcher1 = req.getRequestDispatcher("ServletB");//参数为转发给的路径
        RequestDispatcher requestDispatcher2 = req.getRequestDispatcher("forward.html");

        //2、做出转发动作
        requestDispatcher1.forward(req,resp);
        requestDispatcher2.forward(req,resp);


    }
}
